﻿using System;
using System.Collections.Generic;
using Framework;

namespace Enterprise.Admin.Handle.Download
{
    public partial class GetListJson : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var datas = new List<object>();
            var name = Fq("CoName").SafeToString();
            var pageValue = Fq("page").SafeToInt();
            var rowsValue = Fq("rows").SafeToInt();
            var language = Fq("CoLanguage").SafeToString();
            if (pageValue < 1)
            {
                pageValue = 1;
            }
            if (rowsValue < 1)
            {
                rowsValue = 10;
            }
            var downService = new DownloadService();
            var table = downService.GetTable(name, language, pageValue, rowsValue);
            object result = new { total = table.Total, rows = datas };
            for (int i = 0; i < table.Rows.Count; i++)
            {
                datas.Add(new
                              {
                                  id = table.Rows[i]["CoDownloadId"].SafeToInt(),
                                  CoName = table.Rows[i]["CoName"].SafeToString(),
                                  CoNameEn = table.Rows[i]["CoNameEn"].SafeToString(),
                                  CoType = table.Rows[i]["CoType"].SafeToString(),
                                  CoLanguage = table.Rows[i]["CoLanguage"].SafeToString(),
                                  CoTypeNameEn = table.Rows[i]["CoTypeNameEn"].SafeToString(),
                                  CoTypeName = table.Rows[i]["CoTypeName"].SafeToString(),
                                  CoUrl = table.Rows[i]["CoUrl"].SafeToString(),
                                  CoExtensionName = table.Rows[i]["CoExtensionName"].SafeToString(),
                                  CoFileName = table.Rows[i]["CoFileName"].SafeToString(),
                                  CoSort = table.Rows[i]["CoSort"].SafeToInt(),
                                  CoDate = table.Rows[i]["CoDate"].SafeToDateTime(),

                              });
            }
            Json(result);
        }
    }
}